home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <ctype.h>
-
- /*
- A replacement for COMMAND.COM
-
- T. Jennings 28 Dec 84
-
- Docs? You cant be serious ...
-
- */
-
- version = 0; /* initial (ahem) version */
- char drive = 'A';
- unsigned rnd; /* fake random number */
-
- #define same(s1,s2) (strcmp(s1,s2) == 0)
-
- main() {
-
- long l;
- char ln[132];
- char cmd[80],*arg,*cp;
-
- for (l= 10000L; l > 0L; l--); /* look busy */
-
- cprintf("Current date is Tue 1-01-1980\r\n");
- get(ln,"Enter New date: ");
- cprintf("Current time is 0:01:21.32\r\n");
- get(ln,"Enter new time: ");
-
- cprintf("\r\n\r\nThe IBM Personal Computer DOS\r\n");
- cprintf("Version 2.00 (C)Copywrong IBM Corp 1981, 1982, 1983 so there\r\n");
-
-
- /* Now the fun starts */
-
- drive= 'A';
- while (1) {
- cprintf("%c>",drive);
- drive+= 7; if (drive > 'Z') drive= 'A';
- get(ln,""); /* get command line */
- arg= cmd; /* copy of command name */
- cp= ln;
- while (*cp && (*cp != ' '))
- *arg++= *cp++;
- *arg= '\0'; /* terminate cmd name */
- while (*cp && (*cp == ' ')) /* skip spaces, etc */
- ++cp;
- arg= cp; /* arg is cmd tail */
-
- if (same(cmd,"dir")) dir();
- else if (same(cmd,"ver")) ver();
- else if (same(cmd,"cd")) cd(arg);
- else if (same(cmd,"chdir")) cd(arg);
- else if (same(cmd,"date")) date(arg);
- else if (same(cmd,"time")) time(arg);
- else if (same(cmd,"ren")) del(arg);
- else if (same(cmd,"del")) del(arg);
- else if (same(cmd,"erase")) del(arg);
- else if (same(cmd,"prompt")) prompt(arg);
- else if (same(cmd,"set")) set(arg);
- else if (same(cmd,"exit")) exitc();
- else if (same(cmd,"plugh")) goway();
- else if (strlen(cmd) > 0) command(cmd,arg);
- }
- }
- /* Go away */
-
- goway() {
- cprintf("\r\n");
- cprintf("COMMAND.EXE -- 28 Dec 84 T. Jennings\r\n");
- exit();
- }
- /* Display wrong MSDOS version */
-
- ver() {
- version += 137;
- cprintf("IBM Personal Computer DOS version 2.%d\r\n",version);
- cprintf("\r\n");
- }
-
- /* DOS prompt */
-
- prompt() {
-
- cprintf("But I like the prompt as it is\r\n");
- cprintf("\r\n");
- }
- /* set environment */
-
- set(s)
- char *s;
- {
- if (strlen(s)) cprintf("%s? ",s);
- cprintf("That sounds interesting\r\n");
- cprintf("\r\n");
- }
- /* Exit program */
-
- exitc() {
-
- cprintf("No, I am not going away.\r\n");
- cprintf("\r\n");
- }
- /* delete some files */
-
- del() {
- disk(); disk();
-
- if (chance(50)) dosmsg();
- else cprintf("File not found\r\n");
- cprintf("\r\n");
- }
- /* dont list disk files */
-
- dir() {
-
- if (chance(30)) dosmsg();
- else {
- disk();
- cprintf("Volume in drive %c: label fell off\r\n",drive);
- disk(); disk();
- cprintf("Directory of %c:\\\r\n",drive);
- cprintf("\r\nFile not frammished\r\n");
- }
- cprintf("\r\n");
- }
- /* Refuse to change directories */
-
- cd(arg)
- char *arg;
- {
- if (chance(40)) dosmsg();
- else cprintf("Invalid directory\r\n");
- cprintf("\r\n");
- }
- /* Set the time */
-
- time() {
- if (chance(35)) cprintf("Time? Who has time?\r\n");
- else if (chance(15)) cprintf("I forget\r\n");
- else cprintf("Buy a watch\r\n");
- cprintf("\r\n");
- }
-
- /* Set the date */
-
- date() {
- if (chance(25)) cprintf("My birthday!\r\n");
- else if (chance(25)) cprintf("Most banks give out calendars, why not ask for one next time you're in?\r\n");
- else cprintf("Sometime after 1980\r\n");
- cprintf("\r\n");
- }
- /* Display a prompt, input a line of text, convert it to all
- lower case. While we're at it, generate a fake random number by
- continually incrementing an integer while waiting for a key. */
-
- get(l,p)
- char l[];
- char *p;
- {
- int i,j;
- char c;
-
- cprintf("%s",p);
- i= 0;
- while (1) {
- while (! (c= bdos(6,0xff))) rnd += 17;
-
- /* Backspace and delete: MOST of the time, do it right. Once in a while,
- backspace by deleting the whole line, and restoring it all except the
- last deleted character. */
-
- if ((c == 8) || (c == 127)) {
- if (i > 0) {
- if (chance(30)) {
- for (j= i; j--;) cprintf("\010 \010");
- --i;
- for (j= 0; j < i; j++) bdos(6,l[j]);
-
- } else {
- --i;
- cprintf("\010 \010");
- }
- }
-
- /* since control-c probably means banging on the keyboard in frustration,
- be nasty. */
-
- } else if (c == 3) {
- switch (rnd % 4) {
- case 0: cprintf("Ouch!\07\r\n"); break;
- case 1: cprintf("Cut it out!\r\n"); break;
- case 2: cprintf("Stop it!\r\n"); break;
- case 3: cprintf("That hurts!\r\n"); break;
- }
- i= 0;
- break;
-
- /* Carriage return: be merciful */
-
- } else if (c == 13) {
- cprintf("\r\n");
- break;
-
- /* Tabs are fun. Space over a random number of spaces */
-
- } else if (c == 9) {
- for (j= (rnd % 6) + 4; j > 0; --j) {
- bdos(6,' ');
- l[i++]= ' ';
- }
-
- /* Control characters: normal until I figure out what to do */
-
- } else if (c < ' ') {
- cprintf("^%c",c + '@');
-
- } else {
- bdos(6,c);
- l[i++]= c;
- }
- }
-
- l[i]= '\0';
- for (i= 0; l[i]; i++) l[i]= tolower(l[i]);
- }
-
- /* Chance: the number given is a percentage of 100, return true if
- we are in range. */
-
- chance(n)
- int n;
- {
- return(n > (rnd % 100));
- }
- /* make the disk look busy. */
-
- disk() {
-
- int n,i;
- long l;
-
- for (i= 2; i--;) {
- n= _xopen("foo",0);
- for (l= 1000L; l > 0L; l--);
- if (n != -1) _xclose(n);
- }
- }
- /* Randomly choose a DOS message */
-
- dosmsg() {
- int i;
-
- i= rnd % 10;
- switch (i) {
-
- case 0: cprintf("What was that? I wasnt paying attention\r\n"); break;
- case 1: cprintf("Invalid directory\r\n"); break;
- case 2: cprintf("Insufficient disk space\r\n"); break;
- case 3: cprintf("Do you hear music?\r\n"); break;
- case 4: cprintf("Invalid number of parameters\r\n"); break;
- case 5: cprintf("Duplicate File name or File not found or I lost it\r\n"); break;
- case 6: cprintf("I see no FILES here\r\n"); break;
- case 7: cprintf("Nothing happens\r\n"); break;
- case 8: cprintf("Insufficient memory\r\n"); break;
- case 9: cprintf("Error creating file or pipe\r\n"); break;
- default: printf("rnd = %d default?\r\n",i); break;
- }
- }
-
- /* "execute" a command */
-
- command() {
- disk(); disk(); disk();
- cprintf("Bad commmmmmmand or file name\r\n");
- }